package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.TAccountRecord;
import com.ruoyi.service.ITAccountRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账户操作明细Controller
 * 
 * @author mzr
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/system/operation")
public class TAccountRecordController extends BaseController
{
    @Autowired
    private ITAccountRecordService tAccountRecordService;

    /**
     * 查询账户操作明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:operation:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAccountRecord tAccountRecord)
    {
        startPage();
        List<TAccountRecord> list = tAccountRecordService.selectTAccountRecordList(tAccountRecord);
        return getDataTable(list);
    }

    /**
     * 导出账户操作明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:operation:export')")
    @Log(title = "账户操作明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAccountRecord tAccountRecord)
    {
        //查询该加扣款日志，以及申请单详情
        List<TAccountRecord> list = tAccountRecordService.loadAccountRecordListForExport(tAccountRecord);
        //List<TAccountRecord> list = tAccountRecordService.selectTAccountRecordList(tAccountRecord);
        ExcelUtil<TAccountRecord> util = new ExcelUtil<TAccountRecord>(TAccountRecord.class);
        util.exportExcel(response, list, "账户操作明细数据");
    }

    /**
     * 获取账户操作明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:operation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tAccountRecordService.selectTAccountRecordById(id));
    }

    /**
     * 新增账户操作明细
     */
    @PreAuthorize("@ss.hasPermi('system:operation:add')")
    @Log(title = "账户操作明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAccountRecord tAccountRecord)
    {
        return toAjax(tAccountRecordService.insertTAccountRecord(tAccountRecord));
    }

    /**
     * 修改账户操作明细
     */
    @PreAuthorize("@ss.hasPermi('system:operation:edit')")
    @Log(title = "账户操作明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAccountRecord tAccountRecord)
    {
        return toAjax(tAccountRecordService.updateTAccountRecord(tAccountRecord));
    }

    /**
     * 删除账户操作明细
     */
    @PreAuthorize("@ss.hasPermi('system:operation:remove')")
    @Log(title = "账户操作明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAccountRecordService.deleteTAccountRecordByIds(ids));
    }
}
